In [1]:
import tensorflow as tf
import numpy as np
In [2]:
sess = tf.Session()
In [3]:
x_vals = np.array([1., 3., 5., 7., 9.])
x_data = tf.placeholder(tf.float32)
m_const = tf.constant(3.)
In [4]:
my_product = tf.multiply(x_data, m_const) # 3 * 変数 を表現している
In [5]:
for x_val in x_vals:
print(sess.run(my_product, feed_dict={x_data: x_val})) # feed_dict で placeholder に入る値を定義している
In [6]:
# 供給するデータは 3*5 の行列
input_data = np.array([[1., 3., 5., 7., 9.],
[-2., 0., 2., 4., 6.],
[-6., -3., 0., 3., 6.]])
# 3*5 の行列を2つもつテンソル
x_vals = np.array([input_data, input_data+1])
x_data = tf.placeholder(tf.float32, shape=input_data.shape)
In [7]:
x_vals
Out[7]:
In [8]:
# 定数項
c0 = tf.constant([[1.],[0.],[-1.],[2.],[4.],])
c1 = tf.constant([[2.]])
c2 = tf.constant([[10.]])
In [9]:
# 演算を設定
prod1 = tf.matmul(x_data, c0)
prod2 = tf.matmul(prod1, c1)
add = tf.add(prod2, c2)
In [10]:
for x_val in x_vals:
print(sess.run(add, feed_dict={x_data: x_val}))
In [ ]: